package cn.agiledata.bank.common.notice.logic;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import cn.agiledata.bank.common.service.NotifyMail;
import cn.agiledata.bank.common.util.DateUtil;

import com.vnv.infrastructure.email.service.IMailService;
import com.vnv.infrastructure.email.service.VNVMail;

/**
 * 邮件通知
 * 
 * @author 马贤波
 * 
 */
abstract class EmailNotice extends AbstractNotice {

	protected final static Logger log = Logger.getLogger(NotifyMail.class);

	// 邮件
	private String vmFile;// 邮件模板

	private String emailTitle;// 邮件标题

	// private String contentTitle;// 邮件正文标题
	protected IMailService mailService;// 邮件发送服务

	private List attachment;

	private Map vnvMap;

	protected final void setVnvMap(Map vnvMap) {
		this.vnvMap = vnvMap;
	}

	public void setAttachment(List attachment) {
		this.attachment = attachment;
	}

	// public void setContentTitle(String contentTitle) {
	// this.contentTitle = contentTitle;
	// }

	public void setEmailTitle(String emailTitle) {
		this.emailTitle = emailTitle;
	}

	public void setNotificationService(IMailService notificationService) {
		this.mailService = notificationService;
	}

	public void setVmFile(String vmFile) {
		this.vmFile = vmFile;
	}

	/**
	 * 发送交易相关邮件
	 * 
	 * @param email
	 *            邮件地址
	 * @param vnvMap
	 *            参数变量
	 */
	public void send() {
		VNVMail mail = new VNVMail();

		/** 收信方email* */
		mail.setEmailTo(getReceiver());

		// /** 邮件正文标题 */
		// vnvMap.put("contentTitle", contentTitle);
		/** 邮件签名发送时间 */
		vnvMap.put("sendTime", DateUtil.date2String(new Date()));
		/** 邮件标题* */
		mail.setSubject(emailTitle);
		/** 邮件内容* */
		mail.setContext(this.vnvMap);
		/** 设置模板 */
		mail.setTemplateName(vmFile);
		/** 附件地址 */
		mail.setAttachmentUrl(attachment);
		/** 邮件发送* */

		mailService.sendMail(mail);
		log.debug("邮件发送完成...");
	}

}
